package com.aizhixin.lab.project.course.controller;

import com.aizhixin.lab.account.dto.AccountDTO;
import com.aizhixin.lab.account.service.AccountService;
import com.aizhixin.lab.common.core.ApiReturnConstants;
import com.aizhixin.lab.common.utils.TokenUtil;
import com.aizhixin.lab.project.course.domain.*;
import com.aizhixin.lab.project.course.domain.StuAnswerParamsDomain;
import com.aizhixin.lab.project.course.domain.StuAnswerSaveDomain;
import com.aizhixin.lab.project.course.entity.ExercisesStuStatistics;
import com.aizhixin.lab.project.course.service.TeacherExercisesService;
import com.aizhixin.lab.project.template.domain.ExercisesDomain;
import com.aizhixin.lab.project.template.service.ExercisesService;
import com.aizhixin.lab.task.domain.*;
import com.aizhixin.lab.task.entity.TaskStuInfor;
import com.aizhixin.lab.task.entity.TaskStuStatistics;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/api/v1/teacher/project/exercises")
@RestController
@Api(tags = "习题", value = "习题")
public class TeacherExercisesController {
    @Autowired
    private TeacherExercisesService exercisesService;
    @Autowired
    private AccountService accountService;

    @RequestMapping(value = "/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "新增习题", httpMethod = "POST", notes = "新增习题<br><br><b>lwq</b>")
    public ResponseEntity<?> findTaskInfo(@RequestHeader("Authorization") String token, @RequestBody List<ExercisesDomain> domainList) {
        AccountDTO account = accountService.getUserByToken(token);
        Map<String, Object> result = new HashMap<String, Object>();
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
        result = exercisesService.saveQuestionList(domainList, account);
        return new ResponseEntity(result, HttpStatus.OK);
    }

    @RequestMapping(value = "/importExercises", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "导入习题", httpMethod = "POST", notes = "导入习题<br><br><b>@author lwq</b>")
    public ResponseEntity<?> importFile(@RequestHeader("Authorization") String token,
                                        @ApiParam(value = "Excel数据文件", required = true) @RequestParam(value = "file") MultipartFile file) throws IOException {
        AccountDTO account = accountService.getUserByToken(token);
        Map<String, Object> result = new HashMap<String, Object>();
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
        try {
            exercisesService.exportExercises(file, account.getId());
            result.put(ApiReturnConstants.SUCCESS, true);
            result.put(ApiReturnConstants.MESSAGE, "导入成功");
        } catch (NullPointerException e) {
            result.put(ApiReturnConstants.SUCCESS, false);
            result.put(ApiReturnConstants.MESSAGE, e.getMessage());
        }

        return new ResponseEntity(result, HttpStatus.OK);
    }

    @RequestMapping(value = "/findAllQuestions", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "查看任务或工单下所有试题", httpMethod = "GET", notes = "查看任务或工单下所有试题<br><br><b>lwq</b>")
    public ResponseEntity<?> findTaskInfo(@RequestHeader("Authorization") String token, @RequestParam String id) {
        AccountDTO account = accountService.getUserByToken(token);
        Map<String, Object> result = new HashMap<String, Object>();
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
        List<ExercisesDomain> exercisesDomainList = exercisesService.findAllQuestions(id);
        result.put(ApiReturnConstants.SUCCESS, true);
        result.put(ApiReturnConstants.DATA, exercisesDomainList);
        return new ResponseEntity(result, HttpStatus.OK);
    }

//    @RequestMapping(value = "/importExercises", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
//    @ApiOperation(value = "导入习题", httpMethod = "POST", notes = "导入习题<br><br><b>@author lwq</b>")
//    public ResponseEntity<?> importFile(@RequestHeader("Authorization") String token,
//                                        @ApiParam(value = "Excel数据文件", required = true) @RequestParam(value = "file") MultipartFile file) throws IOException {
//        AccountDTO account = accountService.getUserByToken(token);
//        Map<String, Object> result = new HashMap<String, Object>();
//        if (account == null) {
//            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
//        }
//        try {
//            exercisesService.exportExercises(file, account.getId());
//            result.put(ApiReturnConstants.SUCCESS, true);
//            result.put(ApiReturnConstants.MESSAGE, "导入成功");
//        } catch (NullPointerException e) {
//            result.put(ApiReturnConstants.SUCCESS, false);
//            result.put(ApiReturnConstants.MESSAGE, e.getMessage());
//        }
//
//        return new ResponseEntity(result, HttpStatus.OK);
//    }

    @RequestMapping(value = "/delete", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "删除任务或工单下的习题", httpMethod = "DELETE", notes = "删除任务或工单下的习题<br><br><b>lwq</b>")
    public ResponseEntity<?> delete(@RequestHeader("Authorization") String token, @RequestParam String id) {
        AccountDTO account = accountService.getUserByToken(token);
        Map<String, Object> result = new HashMap<String, Object>();
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
        exercisesService.delete(id);
        result.put(ApiReturnConstants.SUCCESS, true);
        result.put(ApiReturnConstants.MESSAGE, "删除成功");
        return new ResponseEntity(result, HttpStatus.OK);
    }

    @RequestMapping(value = "/releaseExercises", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "发布习题", httpMethod = "POST", notes = "发布习题<br><br><b>lwq</b>")
    public ResponseEntity<?> releaseExercises(@RequestHeader("Authorization") String token, @RequestBody ReleaseExercisesDomain domain) {
        AccountDTO account = accountService.getUserByToken(token);
        Map<String, Object> result = new HashMap<String, Object>();
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
        result = exercisesService.releaseExercises(domain);

        return new ResponseEntity(result, HttpStatus.OK);
    }

    @RequestMapping(value = "/saveExercisesStuAnswer", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "保存学生答案", httpMethod = "POST", notes = "保存学生答案<br><br><b>lwq</b>")
    public ResponseEntity<?> saveExercisesStuAnswer(@RequestHeader("Authorization") String token, @RequestBody StuAnswerSaveDomain domain) {
        AccountDTO account = accountService.getUserByToken(token);
        Map<String, Object> result = new HashMap<String, Object>();
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
        if (!domain.getAnswerList().isEmpty()) {
            for (StuAnswerParamsDomain item : domain.getAnswerList()) {

                if (item.getQuestionType() == 60) {
                    if (item.getStuAnswerAccessorylist() != null && item.getStuAnswerAccessorylist().size() > 0) {
                        continue;
                    }
                    if (item.getLanguage().equals("java")) {
                        if (!item.getStuAnswer().trim().equals("class Main {\n" +
                                "public static void main(String[] args) {\n" +
                                "}\n" +
                                "}") && !item.getStuAnswer().trim().equals("")) {
                            String code[] = item.getStuAnswer().split("\n");
                            for (int i = 0; i < code.length; i++) {
                                String codeStr = code[i];
                                if (i > 1 && i < code.length - 2 && "".equals(codeStr.trim())) {
                                    result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
                                    result.put(ApiReturnConstants.ERROR, "编程题答案为空或最后一行有回车,请删除回车后重新提交！");
                                    return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
                                }
                            }
                        } else {
                            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
                            result.put(ApiReturnConstants.ERROR, "编程题答案为空！");
                            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
                        }
                    }
                    if (item.getLanguage().equals("c")) {
                        if (!item.getStuAnswer().trim().equals("#include <stdio.h>\n" +
                                "int main () {\n" +
                                "return 0;\n" +
                                "}") && !item.getStuAnswer().trim().equals("")) {
                            String code[] = item.getStuAnswer().split("\n");
                            for (int i = 0; i < code.length; i++) {
                                String codeStr = code[i];
                                if (i > 1 && i < code.length - 1 && "".equals(codeStr.trim())) {
                                    result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
                                    result.put(ApiReturnConstants.ERROR, "编程题答案为空或最后一行有回车,请删除回车后重新提交！");
                                    return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
                                }
                            }
                        } else {
                            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
                            result.put(ApiReturnConstants.ERROR, "编程题答案为空！");
                            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
                        }

                    }
                }
            }
        }
        exercisesService.saveExercisesAnswer(domain, account.getId());
        result.put(ApiReturnConstants.SUCCESS, true);
        result.put(ApiReturnConstants.MESSAGE, "保存成功");
        return new ResponseEntity(result, HttpStatus.OK);
    }

    @RequestMapping(value = "/findStuAllQuestionsAndAnswer", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "学生查看试题", httpMethod = "GET", notes = "学生查看试题<br><br><b>lwq</b>")
    public ResponseEntity<?> findStuAllQuestionsAndAnswer(@RequestHeader("Authorization") String token, @RequestParam String id) {
        AccountDTO account = accountService.getUserByToken(token);
        Map<String, Object> result = new HashMap<String, Object>();
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
        List<ExercisesDomain> stuAllQuestionsAndAnswer = exercisesService.findStuAllQuestionsAndAnswer(id);
        result.put(ApiReturnConstants.SUCCESS, true);
        result.put(ApiReturnConstants.DATA, stuAllQuestionsAndAnswer);
        return new ResponseEntity(result, HttpStatus.OK);
    }

    @RequestMapping(value = "/markGrade", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "批阅成绩", httpMethod = "POST", notes = "批阅成绩<br><br><b>lwq</b>")
    public ResponseEntity<?> markGrade(@RequestHeader("Authorization") String token, @RequestBody MarkGradeDomain domain) {
        AccountDTO account = accountService.getUserByToken(token);
        Map<String, Object> result = new HashMap<String, Object>();
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
        exercisesService.markGrade(domain);
        result.put(ApiReturnConstants.SUCCESS, true);
        result.put(ApiReturnConstants.MESSAGE, "批阅成功");
        return new ResponseEntity(result, HttpStatus.OK);
    }

    @RequestMapping(value = "/getStuList", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取同任务习题下学生列表", httpMethod = "GET", notes = "获取同任务习题下学生列表<br><br><b>lwq</b>")
    public ResponseEntity<?> getStuList(@RequestHeader("Authorization") String token, @RequestParam String id) {
        AccountDTO account = accountService.getUserByToken(token);
        Map<String, Object> result = new HashMap<String, Object>();
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
        List<StuInfoDomain> stuList = exercisesService.getStuList(id);
        result.put(ApiReturnConstants.SUCCESS, true);
        result.put(ApiReturnConstants.DATA, stuList);
        return new ResponseEntity(result, HttpStatus.OK);
    }

    @RequestMapping(value = "/findChartData", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "历次提交代码折线统计图数据", httpMethod = "GET", notes = "历次提交代码折线统计图数据")
    public ResponseEntity<?> findEchartData(@RequestHeader("Authorization") String token,
                                            @ApiParam(value = "发布任务题目id", required = true) @RequestParam String exercisesQuestionId,
                                            @ApiParam(value = "学生Id", required = true) @RequestParam String stuId) {
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }
        Integer[] scoreArray = exercisesService.findChartData(exercisesQuestionId, stuId);
        return new ResponseEntity<>(scoreArray, HttpStatus.OK);
    }

    @RequestMapping(value = "/findCodeEvaluating", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "查询代码综合评分", httpMethod = "GET", notes = "查询代码综合评分")
    public ResponseEntity<?> findCodeEvaluating(@RequestHeader("Authorization") String token,
                                                @ApiParam(value = "习题id", required = true) @RequestParam String exercisesQuestionId,
                                                @ApiParam(value = "学生Id", required = true) @RequestParam String stuId) {
        Map<String, Object> result = new HashMap<String, Object>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }
        StuTaskCodeEvaluatingDomain stuTask = exercisesService.findCodeEvaluating(exercisesQuestionId, stuId);
        return new ResponseEntity<>(stuTask, HttpStatus.OK);
    }

    @RequestMapping(value = "/findEvaluationData", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "查询评测统计表", httpMethod = "GET", notes = "查询评测统计表,代码优化建议也在其中")
    public ResponseEntity<?> findEvaluationData(@RequestHeader("Authorization") String token,
                                                @ApiParam(value = "习题id", required = true) @RequestParam String exercisesQuestionId,
                                                @ApiParam(value = "学生Id", required = true) @RequestParam String stuId) {
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }
        ExercisesStuStatistics stuTask = exercisesService.findEvaluationData(exercisesQuestionId, stuId);
        return new ResponseEntity<>(stuTask, HttpStatus.OK);
    }

    @RequestMapping(value = "/findProgrammeAndRubric", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "查询编程题目和其他编程题", httpMethod = "GET", notes = "查询编程题目和其他编程题")
    public ResponseEntity<?> findProgrammeAndRubric(@RequestHeader("Authorization") String token,
                                                    @ApiParam(value = "习题id", required = true) @RequestParam String exercisesQuestionId,
                                                    @ApiParam(value = "任务/工单id", required = true) @RequestParam String taskId) {
        Map<String, Object> result = new HashMap<String, Object>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }
        FindTaskTopicDomain stuTask = exercisesService.findProgrammeAndRubric(exercisesQuestionId, taskId);
        return new ResponseEntity<>(stuTask, HttpStatus.OK);
    }

    @RequestMapping(value = "/findReferenceCode", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "学生提交的代码和老师参考代码", httpMethod = "GET", notes = "学生提交的代码和老师参考代码")
    public ResponseEntity<?> findReferenceCode(@RequestHeader("Authorization") String token,
                                               @ApiParam(value = "习题id", required = true) @RequestParam String exercisesQuestionId,
                                               @ApiParam(value = "学生Id", required = true) @RequestParam String stuId) {
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }
        StuTaskReferenceCodeDomain stuTask = exercisesService.findReferenceCode(exercisesQuestionId, stuId);
        return new ResponseEntity<>(stuTask, HttpStatus.OK);
    }

    @RequestMapping(value = "/getStudentWork", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "查看任务题目列表(包含学生提交答案)并自动批阅填空及选择题", httpMethod = "GET", notes = "查看任务题目列表(包含学生提交答案)<br><br><b>zhengning</b>")
    public ResponseEntity<?> getStudentWork(@RequestHeader("Authorization") String token,
                                            @ApiParam(value = "groupTaskId 学生任务id", required = false) @RequestParam(value = "groupTaskId", required = false) String groupTaskId) {
        Map<String, Object> result = new HashMap<String, Object>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }

        if (StringUtils.isEmpty(groupTaskId)) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "学生任务id不能为空");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }
        StuExercisesQuestionListDomain stuExercisesQuestionListDomain = exercisesService.getStuExercisesQuestionListDomain(groupTaskId);
        result.put(ApiReturnConstants.SUCCESS, Boolean.TRUE);
        result.put(ApiReturnConstants.DATA, stuExercisesQuestionListDomain);

        return new ResponseEntity<Map<String, Object>>(result, HttpStatus.OK);
    }

    @RequestMapping(value = "/findErrorList", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "查看错题列表", httpMethod = "GET", notes = "查看错题列表<br><br><b>lwq</b>")
    public ResponseEntity<?> findErrorList(@RequestHeader("Authorization") String token,
                                           @ApiParam(value = "groupTaskId 任务Id", required = true) @RequestParam(value = "groupTaskId", required = true) String groupTaskId,
                                           @ApiParam(value = "stuId 任务Id", required = true) @RequestParam Long stuId) {
        Map<String, Object> result = new HashMap<String, Object>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }
        if (StringUtils.isEmpty(groupTaskId)) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "任务id不能为空");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }
        result = exercisesService.getErrorList(groupTaskId, stuId);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }
    @RequestMapping(value = "/getModuleAvg", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取非客观题模块平均分", httpMethod = "GET", notes = "获取非客观题模块平均分<br><br><b>hsh</b>")
    public ResponseEntity<?> getModuleAvg(@RequestHeader("Authorization") String token,
                                          @ApiParam(value = "groupTaskId", required = true) @RequestParam(value = "groupTaskId", required = true) String groupTaskId,
                                          @RequestParam(value = "stuId", required = true) Long stuId) {
        AccountDTO account = accountService.getUserByToken(token);
        Map<String, Object> result = new HashMap<String, Object>();
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }
        if (StringUtils.isEmpty(groupTaskId)) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "groupTaskId不能为空");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }
        return new ResponseEntity<>(exercisesService.getAvg(groupTaskId,stuId), HttpStatus.OK);
    }
    @RequestMapping(value = "/getStuComment", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取点评", httpMethod = "GET", notes = "获取点评<br><br><b>lwq</b>")
    public ResponseEntity<?> findErrorList(@RequestHeader("Authorization") String token,
                                           @ApiParam(value = "groupTaskId 任务Id", required = true) @RequestParam(value = "groupTaskId", required = true) String groupTaskId) {
        Map<String, Object> result = new HashMap<String, Object>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }
        if (StringUtils.isEmpty(groupTaskId)) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "任务id不能为空");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }
        result = exercisesService.getStuComment(groupTaskId);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }
    @RequestMapping(value = "/getIsSetTime", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "是否需要倒计时", httpMethod = "GET", notes = "是否需要倒计时<br><br><b>lwq</b>")
    public ResponseEntity<?> getIsSetTime(@RequestHeader("Authorization") String token,
                                           @ApiParam(value = "groupTaskId 任务Id", required = true) @RequestParam(value = "groupTaskId", required = true) String groupTaskId) {
        Map<String, Object> result = new HashMap<String, Object>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }
        if (StringUtils.isEmpty(groupTaskId)) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "任务id不能为空");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }
        result = exercisesService.getIsSetTime(groupTaskId);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }
}
